package com.bree.erp.jsf.datatable;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.bree.erp.entity.CrudId;

public class ListBreeDataModel<E extends CrudId<Long>> extends ListDataModel<E> implements SelectableDataModel<E> {
	
	
	private List<E> refList;
	
	public ListBreeDataModel(List<E> list) {
		
		super(list);
		
		this.refList = list;
	}
	
	
	@Override
	public E getRowData(String rowKey) {
		
		if(refList != null && rowKey != null) {
			for(E item : refList) {
				Long id = item.getId();
				
				if(id != null && rowKey.equals(id.toString())) {
					return item;
				}
			}
		}
		
		return null;
	}

	@Override
	public Object getRowKey(E row) {
		return row.getId();
	}
	
}
